<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
            已知数据结构 users, 请实现语法支持 users.unique() 能够按 name 字段去重, 并输出数据结构为: [“a”, “b”]
            const users = [
            {id:1, name:“a”},
            {id:2, name:“a”},
            {id:3, name:“b”},
            {id:4, name:“b”}
        */
        const users = [{
                id: 1,
                name: 'a'
            },
            {
                id: 2,
                name: 'a'
            },
            {
                id: 3,
                name: 'b'
            },
            {
                id: 4,
                name: 'b'
            }
        ]

        users.unique = function () {
            let data = this;
            let set = new Set();

            for (let i = 0; i < data.length; i++) {
                if (set.has(data[i].name)) {
                    continue;
                } else {
                    set.add(data[i].name)
                }
            }

            return console.log([...set]);
        }

        users.unique();
    </script>
</body>

</html>